home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / fredfish / 1059.lha / Programs / MathPlot / Macros / Grid.mapl < prev    next >
Text File  |  1994-12-15  |  5KB  |  271 lines

  1. /* Plots a grid. */
  2. /* Version 1.50, 07.08.1993 */
  3.  
  4. options results
  5.  
  6.  
  7. IF ~SHOW('L','rexxmathlib.library') THEN
  8.    CALL ADDLIB('rexxmathlib.library',0,-30)
  9.  
  10. /* First, get some infos from the program */
  11.  
  12. getintervall2 stem intervall.
  13. evalstring intervall.xmin
  14. xmn = result
  15. evalstring intervall.xmax
  16. xmp = result
  17. evalstring intervall.ymin
  18. ymn = result
  19. evalstring intervall.ymax
  20. ymp = result
  21.  
  22. xmodem = 1
  23. ymodem = 1
  24. if(intervall.xmode = 1) then xmodem = 2.718281828
  25. if(intervall.ymode = 1) then ymodem = 2.718281828
  26. if(intervall.xmode = 2) then xmodem = 3.141592654
  27. if(intervall.ymode = 2) then ymodem = 3.141592654
  28.  
  29. /* Calc dx and dy */
  30. dx = (xmp-xmn)/200
  31. dy = (ymp-ymn)/200
  32.  
  33. info stem b.
  34. resx   = b.resx
  35. resy   = b.resy
  36. colors = b.colors
  37.  
  38. xm = (resx-1)/(xmp-xmn)
  39. ym = (resy-1)/(ymp-ymn)
  40.  
  41. /* Calc the tics */
  42. xtics = maketics(xmn, xmp, 0, 10)
  43. ytics = maketics(ymn, ymp, 0, 10)
  44.  
  45. flx = floor(xmn/xtics)
  46. fly = floor(ymn/ytics)
  47. clx = ceil(xmp/xtics)
  48. cly = ceil(ymp/ytics)
  49.  
  50. /* Draw the tics */
  51. drawtics(xtics*flx, xtics, xtics*clx,
  52.         ,ytics*fly, ytics, ytics*cly,
  53.         ,xm,ym)
  54. exit
  55.  
  56. /* ------------------------------------------------------------*/
  57. /* Function MakeTics */
  58. maketics:
  59. parse arg tmin, tmax, logscale, baselog
  60.  
  61. x = tmin-tmax
  62.  
  63. xr  = fabs(x)
  64. l10 = log10(xr)
  65. if(l10 >= 0.0) then do
  66.  i = floor(l10)
  67.  end
  68. else do
  69.  i = ceil(l10-1.0)
  70. end
  71.  
  72. if(logscale) then do
  73.   tic = raise(baselog, i)
  74.  if(tic < 1.0) then tic = 1.0
  75. end
  76. else do
  77.  xnorm = pow(10.0, l10-i)
  78.  if(xnorm <= 2.01) then do
  79.   tics = 0.2
  80.   end
  81.  else do
  82.   if(xnorm <= 5) then do
  83.    tics = 0.5
  84.    end
  85.   else do
  86.    tics = 1.0
  87.   end
  88.  end
  89.   tic = tics * raise(10.0,i)
  90. end
  91. return tic
  92.  
  93.  
  94. /* ------------------------------------------------------------*/
  95. /* Function RAISE */
  96. raise:
  97. parse arg x,y
  98.  
  99. val = 1.0
  100. do i=0 to abs(y)-1
  101.  val = val*x
  102. end
  103.  
  104. if(y < 0) then val = 1/val
  105.  
  106. return val
  107.  
  108.  
  109. /* ------------------------------------------------------------*/
  110. /* DrawTics */
  111. drawtics:
  112. parse arg xstart, xdiff, xendorig, ystart, ydiff, yendorig, xm, ym
  113.  
  114.  
  115. /* Round a bit */
  116. xend = xendorig * 1.001
  117. yend = yendorig * 1.001
  118.  
  119. a = 0
  120. b = 0
  121.  
  122. e    = exp(1)
  123. pi   = 2*acos(0)
  124. ln10 = ln(10)
  125.  
  126.  
  127. select
  128.  when intervall.xmode=0 then do
  129.   do pos1 = xstart to xend by xdiff
  130.    x.a   = pos1
  131.    xmd.a = x.a-dx
  132.    xpd.a = x.a+dx
  133.    a   = a+1
  134.   end
  135.  end
  136.  when intervall.xmode=1 then do
  137.   do pos1 = xstart to xend by xdiff
  138.    x.a   = pos1*e
  139.    xmd.a = x.a-dx*e
  140.    xpd.a = x.a+dx*e
  141.    a   = a+1
  142.   end
  143.  end
  144.  when intervall.xmode=2 then do
  145.   do pos1 = xstart to xend by xdiff
  146.    x.a   = pos1*pi
  147.    xmd.a = x.a-dx*pi
  148.    xpd.a = x.a+dx*pi
  149.    a   = a+1
  150.   end
  151.  end 
  152.  when intervall.xmode=3 then do
  153.   do pos1 = xstart to xend by xdiff
  154.    x.a   = exp(pos1)
  155.    xmd.a = exp(pos1-dx)
  156.    xpd.a = exp(pos1+dx)
  157.    a   = a+1
  158.   end
  159.  end 
  160.  when intervall.xmode=4 then do
  161.   do pos1 = xstart to xend by xdiff
  162.    x.a   = exp(pos1*ln10)
  163.    xmd.a = exp((pos1-dx)*ln10)
  164.    xpd.a = exp((pos1+dx)*ln10)
  165.    a   = a+1
  166.   end
  167.  end 
  168.  otherwise nop
  169. end
  170.  
  171.  
  172. select
  173.  when intervall.ymode=0 then do
  174.   do pos1 = ystart to yend by ydiff
  175.    y.b   = pos1
  176.    ymd.b = y.b-dy
  177.    ypd.b = y.b+dy
  178.    b   = b+1
  179.   end
  180.  end
  181.  when intervall.ymode=1 then do
  182.   do pos1 = ystart to yend by ydiff
  183.    y.b   = pos1*e
  184.    ymd.b = y.b-dy*e
  185.    ypd.b = y.b+dy*e
  186.    b   = b+1
  187.   end
  188.  end
  189.  when intervall.ymode=2 then do
  190.   do pos1 = ystart to yend by ydiff
  191.    y.b   = pos1*pi
  192.    ymd.b = y.b-dy*pi
  193.    ypd.b = y.b+dy*pi
  194.    b   = b+1
  195.   end
  196.  end 
  197.  when intervall.ymode=3 then do
  198.   do pos1 = ystart to yend by ydiff
  199.    y.b   = exp(pos1)
  200.    ymd.b = exp(pos1-dy)
  201.    ypd.b = exp(pos1+dy)
  202.    b   = b+1
  203.   end
  204.  end 
  205.  when intervall.ymode=4 then do
  206.   do pos1 = ystart to yend by ydiff
  207.    y.b   = exp(pos1*ln10)
  208.    ymd.b = exp((pos1-dy)*ln10)
  209.    ypd.b = exp((pos1+dy)*ln10)
  210.    b   = b+1
  211.   end
  212.  end 
  213.  otherwise nop
  214. end
  215.  
  216.  
  217. minx = (xmp-xmn)*xmodem/1000
  218. miny = (ymp-ymn)*ymodem/1000
  219.  
  220.  
  221. /* Reset plotcolor */
  222. getcolor plotcolor
  223. oldcolor = result
  224.  
  225. /* Ask plotcolor */
  226. /* First generate the button-string */
  227. select
  228.  when colors = 2 then do
  229.   but = "1|Cancel"
  230.  end
  231.  when colors = 4 then do
  232.   but = "1|2|3|Cancel"
  233.  end
  234.  when colors = 8 then do
  235.   but = "1|2|3|4|5|6|7|Cancel"
  236.  end
  237.  when colors = 16 then do 
  238.   but = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Cancel"
  239.  end
  240.  when colors = 32 then do
  241.   /* 32 colors does not make sense here */
  242.   but = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|Cancel"
  243.  end
  244. end
  245.  
  246. text = 'title "GridLines" prompt "Select a color" button ' || but
  247.  
  248. /* Now ask */
  249. requestresponse text
  250.  
  251. if RC == 5 then exit
  252.  
  253. setcolor plotcolor result
  254.  
  255.  
  256. /* Plot a cross, but only if NOT on an axis */
  257. do i=0 to a-1
  258.  do j=0 to b-1
  259.   if (abs(x.i) > minx) then do
  260.    if(abs(y.j) > miny) then do 
  261.     line xmd.i  y.j    xpd.i  y.j
  262.     line x.i    ymd.j  x.i    ypd.j
  263.    end
  264.   end
  265.  end
  266. end
  267.  
  268. setcolor plotcolor oldcolor
  269.  
  270. return 0
  271.